package com.base.organization;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.infomanage.bean.SearchBean;
import com.infomanage.dao.BaseDAO;
import com.infomanage.exception.DaoException;
import com.infomanage.po.HibernateSessionFactory;

public class OrganizationDAO extends BaseDAO<Organization>{

	public Organization find(int orgId) throws DaoException{
		return super.find(Organization.class, orgId);
	}
	
	public List<Organization> findAll() throws DaoException{
		return super.findAll(Organization.class);
	}
	
	@SuppressWarnings("unchecked")
	public List<Organization> findChildren(int orgId) throws DaoException{
		Session session = HibernateSessionFactory.getSession();
		List<Organization> list = null;
		try {
			Query query =  session.createQuery("from Organization where parent = ?");
			query.setInteger(0, orgId);
			list = query.list();
		} catch (Exception e) {
			throw new DaoException(e);
		} finally {
			HibernateSessionFactory.closeSession();
		}
		return list;
	}
	
	public List<Organization> findByFields(SearchBean searchBean) throws DaoException{
		return super.findByFields(Organization.class, searchBean);
	}
}
